<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<link rel="stylesheet"
			href="${pageContext.request.contextPath }/css/base.css" />
		<link rel="stylesheet"
			href="${pageContext.request.contextPath }/css/info-mgt.css" />
		<link rel="stylesheet"
			href="${pageContext.request.contextPath }/css/WdatePicker.css" />
		<title>移动办公自动化系统</title>
		<script type="text/javascript"
			src="${pageContext.request.contextPath }/js/jquery.js">
</script>

		<script type="text/javascript">

	function showTable(operation){
		var cp;
		if(operation=='end'){
			cp=$("#allpage").text();
		}
		if(operation=='back'){
			cp=$("#nowpage").text()==1?1:$("#nowpage").text()-1;
		}
		if(operation=='next'){
			var now=$("#nowpage").text();
			var all=$("#allpage").text();
			var ne=parseInt($("#nowpage").text())+1; 
			cp=now==all?now:ne;
		}
		$.ajax({
			type:"post",
			url:"ContactManager.action?method=ajaxquery&currPage="+cp,
			success:function(page){
				
				if(operation=="end" || operation=="start" || operation=="back" ||operation=="next"){
				var el = document.getElementById("body_id");
			    el.parentNode.removeChild(el);
				}
				
				var data=page.filesData;
				$("#nowpage").html(page.currentPage);
				$("#allpage").html(page.totalPage);
				
				var tbodyObj = document.createElement("tbody");
				tbodyObj.id="body_id";
				var tableObj = document.getElementById("data_id");
				tableObj.appendChild(tbodyObj);
				for(var i=0;i<data.length;i++){
					var trObj=document.createElement("tr");
					var td_id=document.createElement("td");
					td_id.innerHTML=data[i].recordId;
					var td_name=document.createElement("td");
					td_name.innerHTML=data[i].userName;
					td_name.id="td"+i;
					var td_deptname=document.createElement("td");
					td_deptname.innerHTML=data[i].deptName;
					var td_sure=document.createElement("td");
					td_sure.innerHTML="<a href='javascript:void(0);' onclick='test("+i+","+data[i].recordId+");'>添加</a>";
					 //把td添加到对应的tr中
	     	 		 trObj.appendChild(td_id);
	     	 		 trObj.appendChild(td_name);
	     	 		 trObj.appendChild(td_deptname); 	 
	     	 		 trObj.appendChild(td_sure); 
	     	 		 //把tr对象添加到tbody中
	     	  		 tbodyObj.appendChild(trObj);
				}
			}
		});
	}
	function test(id,recordid){
		window.returnValue=$("#td"+id).text()+"/"+recordid;
		window.close();
	}
</script>
	</head>

	<body onload="showTable(1);">
		<div class="title">
			<h2>
				联系人
			</h2>
		</div>
		<table id="data_id">
			<thead>
				<tr>
					<th class="num">
						编号
					</th>
					<th class="name">
						姓名
					</th>
					<th class="name">
						所在部门
					</th>
					<th class="operate">
						操作
					</th>
				</tr>
			</thead>
		</table>
		<table>
			<tr>
				<td>
					<a onclick="showTable('start');">首页</a>
				</td>
				<td>
					<a onclick="showTable('back');">上一页</a>
				</td>
				<td>
					<a onclick="showTable('next');">下一页</a>
				</td>
				<td>
					<a onclick="showTable('end');">末页</a>
				</td>
				<td>
					当前页码:<label id="nowpage"></label>/<label id="allpage"></label>
				</td>
			</tr>
		</table>
	</body>
</html>
